<script setup lang="ts">
import type { patientConsultOrderItem } from '@/types/consult'
import { OrderType } from '@/enums'
import { useOrderCancel, useOrderDel, useLook } from '@/composable/index'

// import { patientOrder } from '@/api/consult'
// import { showSuccessToast } from 'vant'
// import { ref } from 'vue'
// import { onMounted } from 'vue'

const props = defineProps<{
  item: patientConsultOrderItem
}>()
const emits = defineEmits<{
  (e: 'delEvent', id: string): void
}>()

/*
取消问诊
1：调用接口实现取消
2：改变状态
*/
const { loading, cancelEvent } = useOrderCancel()

/*
删除问诊
1：调用删除接口
2：删除相应条数据
*/
// const callback = (id: string) => {
//   emits('delEvent', id)
// }

//

const { delLoading, delEvent } = useOrderDel((id: string) => {
  emits('delEvent', id)
})

// 查看处方
const { lookEvent } = useLook()

const onselect = (res: any, index: number) => {
  console.log(res, index)
  if (index === 1) {
    delEvent(props.item.id)
  }
}
</script>

<template>
  <div class="consult-item">
    <div class="head van-hairline--bottom">
      <img class="img" src="@/assets/avatar-doctor.svg" />
      <p>极速问诊（自动分配医生）</p>
      <span>{{ item.statusValue }}</span>
    </div>
    <div class="body">
      <div class="body-row">
        <div class="body-label">病情描述</div>
        <div class="body-value">{{ item.illnessDesc }}</div>
      </div>
      <div class="body-row">
        <div class="body-label">价格</div>
        <div class="body-value">¥ {{ item.payment }}</div>
      </div>
      <div class="body-row">
        <div class="body-label">创建时间</div>
        <div class="body-value tip">{{ item.createTime }}</div>
      </div>
    </div>
    <div class="foot" v-if="item.status === OrderType.ConsultPay">
      <van-button
        class="gray"
        plain
        size="small"
        round
        :loading="loading"
        @click="cancelEvent(item)"
        >取消问诊</van-button
      >
      <van-button type="primary" plain size="small" round>去支付</van-button>
    </div>
    <div class="foot" v-if="item.status === OrderType.ConsultWait">
      <van-button
        class="gray"
        plain
        size="small"
        round
        :loading="loading"
        @click="cancelEvent(item)"
        >取消问诊</van-button
      >
      <van-button type="primary" plain size="small" round :to="`/room?orderId=${item.id}`"
        >继续沟通</van-button
      >
    </div>
    <div class="foot" v-if="item.status === OrderType.ConsultChat">
      <van-button
        v-if="item.prescriptionId"
        class="gray"
        plain
        size="small"
        round
        @click="lookEvent(item.prescriptionId)"
        >查看处方</van-button
      >
      <van-button type="primary" plain size="small" round :to="`/room?orderId=${item.id}`"
        >继续沟通</van-button
      >
    </div>
    <div class="foot" v-if="item.status === OrderType.ConsultComplete">
      <van-popover
        :actions="[{ text: '查看处方', disabled: !item.prescriptionId }, { text: '删除订单' }]"
        @select="onselect"
      >
        <template #reference>
          <van-button class="gray" plain size="small" round>更多</van-button>
        </template>
      </van-popover>

      <van-button type="primary" plain size="small" round :to="`/room?orderId=${item.id}`"
        >问诊记录</van-button
      >
      <van-button type="primary" plain size="small" round>{{
        item.evaluateId ? '查看评价' : '去评价'
      }}</van-button>
    </div>
    <div class="foot" v-if="item.status === OrderType.ConsultCancel">
      <van-button
        class="gray"
        plain
        size="small"
        round
        :loading="delLoading"
        @click="delEvent(item.id)"
        >删除订单</van-button
      >
      <van-button type="primary" plain size="small" round to="/">咨询其它医生</van-button>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.consult-item {
  border-radius: 4px;
  box-shadow: 0px 0px 22px 0px rgba(245, 245, 245, 0.1);
  background-color: #fff;
  margin-bottom: 10px;
  .head {
    display: flex;
    align-items: center;
    height: 50px;
    padding: 0 15px;
    .img {
      width: 20px;
      height: 20px;
    }
    > p {
      flex: 1;
      font-size: 15px;
      padding-left: 10px;
    }
    > span {
      color: var(--cp-tag);
      &.orange {
        color: #f2994a;
      }
      &.green {
        color: var(--cp-primary);
      }
    }
  }
  .body {
    padding: 15px 15px 8px 15px;
    .body-row {
      display: flex;
      margin-bottom: 7px;
    }
    .body-label {
      width: 62px;
      font-size: 13px;
      color: var(--cp-tip);
    }
    .body-value {
      width: 250px;
      &.tip {
        color: var(--cp-tip);
      }
    }
  }
  .foot {
    padding: 0 15px 15px 15px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .van-button {
      margin-left: 10px;
      padding: 0 16px;
      &.gray {
        color: var(--cp-text3);
        background-color: var(--cp-bg);
      }
    }
    .more {
      color: var(--cp-tag);
      flex: 1;
      font-size: 13px;
    }
  }
}
</style>
